//    Copyright (C) Kherty.  All rights reserved.
using System.Collections;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet
{

    /// <summary>
    /// Represents the calculation properties of a worksheet
    /// </summary>
    public class CalculationProperties: IOfficeXmlSerializable
    {
        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read("calcPr"))
            {
                _calcId = c.GetInteger("calcId");
                _calcMode = c.GetOptionalEnum("calcMode", CalculationMode.Automatic);
                _fullCalcOnLoad = c.GetOptionalBoolean("fullCalcOnLoad", false);
                RefMode = c.GetOptionalEnum("refMode", ReferenceMode.A1);
                _iterate = c.GetOptionalBoolean("iterate", false);
                _iterateCount = c.GetOptionalInteger("iterateCount", 100);
                IterateDelta = c.GetOptionalDouble("iterateDelta", 0.001);
                _fullPrecision = c.GetOptionalBoolean("fullPrecision", true);
                _calcCompleted = c.GetOptionalBoolean("calcCompleted", true);
                calcOnSave = c.GetOptionalBoolean("calcOnSave", true);
                _concurrentCalc = c.GetOptionalBoolean("concurrentCalc", true);
                ConcurrentManualCount = c.GetOptionalUIntegerAsInteger("concurrentManualCount");
                ForceFullCalc = c.GetOptionalBoolean("forceFullCalc", false); //\\defaultOK?
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("calcPr"))
            {
                c.SetInteger("calcId", _calcId);
                c.SetOptionalEnum("calcMode", _calcMode, CalculationMode.Automatic);
                c.SetOptionalBoolean("fullCalcOnLoad",_fullCalcOnLoad , false);
                c.SetOptionalEnum("refMode", RefMode, ReferenceMode.A1);
                c.SetOptionalBoolean("iterate",_iterate , false);
                c.SetOptionalInteger("iterateCount",_iterateCount , 100);
                c.SetOptionalDouble("iterateDelta",IterateDelta , 0.001);
                c.SetOptionalBoolean("fullPrecision",_fullPrecision , true);
                c.SetOptionalBoolean("calcCompleted",_calcCompleted , true);
                c.SetOptionalBoolean("calcOnSave",calcOnSave , true);
                c.SetOptionalBoolean("concurrentCalc",_concurrentCalc , true);
                c.SetOptionalUIntegerAsInteger("concurrentManualCount", ConcurrentManualCount);
                c.SetOptionalBoolean("forceFullCalc",ForceFullCalc , false); //\\defaultOK?
            }
        }

        #endregion

        private bool _forceFullCalc;

        public bool ForceFullCalc
        {
            get { return _forceFullCalc; }
            set { _forceFullCalc = value; }
        }
	

        private int? _concurrentManualCount;

        public int? ConcurrentManualCount
        {
            get { return _concurrentManualCount; }
            set { _concurrentManualCount = value; }
        }
	

        private bool _concurrentCalc = true;

        public bool ConcurrentCalc
        {
            get { return _concurrentCalc; }
            set { _concurrentCalc = value; }
        }
	
        private bool calcOnSave = true;

        public bool CalcOnSave
        {
            get { return calcOnSave; }
            set { calcOnSave = value; }
        }
	
        private bool _calcCompleted = true;

        public bool CalcCompleted
        {
            get { return _calcCompleted; }
            set { _calcCompleted = value; }
        }
	
        private bool _fullPrecision = true;

        public bool FullPrecision
        {
            get { return _fullPrecision; }
            set { _fullPrecision = value; }
        }

        private double _iterateDelta = 0.001;

        public double IterateDelta
        {
            get { return _iterateDelta; }
            set { _iterateDelta = value; }
        }


        private int _iterateCount = 100;

        public int IterationCount //\\merge with iterate?
        {
            get { return _iterateCount; }
            set { _iterateCount = value; }
        }
	

        private bool _iterate;

        public bool Iterate
        {
            get { return _iterate; }
            set { _iterate = value; }
        }
	

        private ReferenceMode _refMode;

        public ReferenceMode RefMode
        {
            get { return _refMode; }
            set { _refMode = value; }
        }
	

        private bool _fullCalcOnLoad;

        public bool FullCalcOnLoad
        {
            get { return _fullCalcOnLoad; }
            set { _fullCalcOnLoad = value; }
        }
	

        private CalculationMode _calcMode;

        public CalculationMode CalculationMode
        {
            get { return _calcMode; }
            set { _calcMode = value; }
        }
	

        private int _calcId;

        public int CalcId
        {
            get { return _calcId; }
            set { _calcId = value; }
        }
	
    }
}
